home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-11 / nan_s789.zip / S50009.TXT < prev   
Text File  |  1992-02-15  |  8KB  |  229 lines

  1. CLIPPER 5.0 SUPPORT BULLETIN #9
  2.  
  3. BULLETIN REVISED: 22nd Jan, 1992
  4.  
  5. PRODUCT: Clipper 5.0
  6.  
  7. AFFECTED VERSIONS: 5.01
  8.  
  9. SUBJECT: Clipper File Structures
  10.  
  11.  
  12. DATABASE (.dbf) FILE FORMAT
  13. ---------------------------
  14.  
  15. All numbers are expressed in decimal unless otherwise 
  16. noted.
  17.  
  18.  
  19. (.dbf) HEADER STRUCTURE
  20.  
  21. Offset  Format      Contents
  22. ------  ----------- --------------------------------------
  23. 0       03 or 083h  Signature Byte:
  24.                     03--(.dbf) with no memo (.dbt) file
  25.                     131 (083h)--(.dbf) with memo (.dbt) 
  26.                     file
  27. 1       Year        Last update year without century (1991 
  28.                     = 91)
  29. 2       01 to 12    Month of last update
  30. 3       01 to 31    Day of last update
  31. 4-7     long        Number of records
  32. 8-9     word        Location in file where data begins 
  33.                     (START)
  34. 10-11   word        Record length (field sizes plus 1)
  35. 12-31   N/A         Reserved
  36.  
  37. Field definitions begin at byte 32 and are 32 bytes long.  
  38. The last field structure is followed by a constant 13 (0Dh) 
  39. and a constant 0 (00h) indicating the end of the field 
  40. structures.  This is a deviation from the dBASE III+ 
  41. format, which does not have the 0 (00h) byte.
  42.  
  43. Each field structure is composed in the following manner:
  44.  
  45.  
  46. FIELD DEFINITION STRUCTURE (Repeat for each field)
  47.  
  48. Offset  Format        Contents
  49. ------  ------------  -------------------------------------
  50. 0-10    character     Field Name (printable string; no 
  51.                       spaces;
  52.                       NUL terminated; NUL padded)
  53. 11      character     Field Type (Character, Logical, Memo, 
  54.                       Numeric, or Date)
  55. 12-15   N/A           Reserved
  56. 16      unsigned int  Total length, including decimal for 
  57.                       numerics (referred to in text as 
  58.                       LENGTH)
  59. 17      unsigned int  Number of decimal places
  60. 18-31   N/A           Reserved
  61.  
  62. At START (defined above), the record data begins.  Each 
  63. field is stored sequentially according to the order in the 
  64. header.  Before each record is a deleted flag which is 
  65. either a space or an asterisk ("*").  If the deleted flag 
  66. is an asterisk, the record is assumed to be deleted.  The 
  67. field length specified in the header includes the deleted 
  68. flag.  Below is a brief definition of each field type, and 
  69. the method of storage employed.
  70.  
  71.  
  72. Character (Field Type = "C")
  73.  
  74. Character fields may contain any ASCII character from 0 to 
  75. 255, and are always of a static length (defined by LENGTH 
  76. in the field structure definition).  Note that the string 
  77. is not NUL terminated.  An empty character field contains 
  78. all spaces (32, 20h).
  79.  
  80.  
  81. Numeric (Field Type = "N")
  82.  
  83. Numerics are stored as character equivalents with the 
  84. decimal included.  There is no decimal character if the 
  85. number of decimal places is zero.  Empty numerics are 
  86. padded with leading spaces, have a zero before the decimal 
  87. point, and zero padding after the decimal point to the end 
  88. of the field.  An empty numeric of length 9 with 2 decimals 
  89. would look like this: "     0.00".
  90.  
  91.  
  92. Logical (Field Type = "L")
  93.  
  94. Logical fields are stored as a single character.  "T" is 
  95. stored for true.  All other characters are assumed to 
  96. equate to a false value (though "F" is most likely to be 
  97. used).  An empty logical contains an "F" character.
  98.  
  99.  
  100. Date (Field Type = "D")
  101.  
  102. Date fields are exactly eight characters in length.  A date 
  103. field is stored in the format YYYYMMDD where YYYY = Year 
  104. with century, MM = Month, and DD = Day.  10/20/82 would be 
  105. stored as "19821020".
  106.  
  107.  
  108. Memo Fields (Field Type = "M")
  109.  
  110. Memo fields are always ten bytes in length.  The ten bytes 
  111. hold a pointer to the first 512 byte block in a (.dbt) file 
  112. that contains the memo text.  The pointer is in ASCII--all 
  113. spaces indicates that there is no memo text for that field.
  114.  
  115. ----------------------------------------------------------
  116.  
  117.  
  118. MEMO (.dbt) FILE FORMAT
  119. -----------------------
  120.  
  121. Clipper (.dbt) files are no different than dBASE III+ 
  122. (.dbt) files.  They are treated as if they are an integral 
  123. part of the (.dbf) file.  If the (.dbf) is moved, the 
  124. (.dbt) is moved also, etc.
  125. Memo files are divided into 512 byte blocks.  The first 
  126. block is a header and has a very simple format:
  127.  
  128.  
  129. (.dbt) FILE HEADER STRUCTURE
  130.  
  131. Offset  Format  Contents
  132. ------  ------  ---------------------------------------
  133. 0-3     Long    Number of 512-byte blocks in the file, 
  134.                 including the header
  135. 4-511   Unused  Reserved
  136.  
  137. The data blocks also have a simple format: they simply 
  138. contain the data terminated by a Ctrl-Z (01Ah, 26 decimal).  
  139. Memos may be up to 64K in length.  If the memo field does 
  140. not contain an even multiple of 512 bytes, the unused 
  141. remainder of the block is padded to 512 bytes with spaces.
  142.  
  143. ----------------------------------------------------------
  144.  
  145.  
  146. INDEX (.ntx) FILE FORMAT
  147. ------------------------
  148.  
  149. Clipper uses a modified B+-Tree style index structure.  
  150. Each file consists of pages that are 1024 bytes long.  The 
  151. first page is a header which has the following structure:
  152.  
  153.  
  154. INDEX (.ntx) FILE HEADER STRUCTURE
  155.  
  156. Offset  Format  Contents
  157. ------  ------  ------------------------------------------
  158. 0-1     Word    Signature Byte
  159.                 03 = Index file
  160. 2-3     Word    Clipper indexing version number
  161. 4-7     Long    Offset in file for first index page
  162. 8-11    Long    Offset to an unused key page
  163. 12-13   Word    Key size + 8 bytes (distance between key 
  164.                 pages)
  165. 14-15   Word    Key size
  166. 16-17   Word    Number of decimals in key (if numeric)
  167. 18-19   Word    Maximum entries per page
  168. 20-21   Word    Minimum entries per page or half page (The 
  169.                 first, or root page of an index has a 
  170.                 minimum of 1 entry regardless of this 
  171.                 value)
  172. 22-277  256     Key expression, followed by CHR(0)
  173.         bytes
  174. 278     Byte    1 if index is unique, 0 if not.
  175. 279     744     Filler (pads to 1024)
  176.         bytes
  177.  
  178.  
  179. Index key pages consist of the following structure:
  180.  
  181.  
  182. INDEX KEY PAGES
  183.  
  184. Offset    Format         Contents
  185. --------- -------------  ------------------------------------
  186. 0-1       Word           Number of used entries on this page 
  187.                          (this number will be between the 
  188.                          Minimum and Maximums defined in the 
  189.                          header unless it is the root page)
  190. 2         unsigned ptrs  An array of unsigned longs begins 
  191.                          here.  The array length is equal to 
  192.                          the maximum number of key entries 
  193.                          per page +1.  They contain offsets 
  194.                          onto the page where the key values 
  195.                          (ITEMS) are located.
  196. Remainder of page        ITEM entries (described below)
  197.  
  198. Following the array of unsigned pointers to offsets in the 
  199. page are the key value entries.  These so-called ITEM 
  200. entries describe a key value and its record's position in 
  201. the database.  The key value is always stored as a 
  202. character string, regardless of its type.
  203.  
  204.  
  205. ITEM Entry Structure
  206.  
  207. Offset  Format    Contents
  208. ------  --------- ----------------------------------------
  209. 0-1     Long      Pointer to a page in the index file, 
  210.                   containing keys that are prior to this 
  211.                   key.
  212. 2-3     Long      Record number in controlling database 
  213.                   file.
  214. 4       Character Key value.  This field begins at offset 4 
  215.                   and continues for the length of the key.  
  216.                   Numerics are padded with leading zeros.
  217.  
  218.  
  219. For more information about traversing Clipper (.ntx) files, 
  220. you may want to reference the following books:
  221.  
  222. Spence, Rick.  Clipper Programming Guide, Second Edition. 
  223. (Microtrend Books, Slawson Communications, Inc.; ISBN 0-915391-41-
  224. 4)
  225. Tenenbaum, A.M. et al., Data Structures Using C. (Prentice-Hall).
  226.  
  227.  
  228. END: CLIPPER 5.0 SUPPORT BULLETIN #9
  229.